import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import { getLoginUserUsingGet } from '@/api/userController.ts'

export const useLoginUserStore = defineStore('counter', () => {
  // 定义初始值
  const loginUser = ref<API.UserLoginVO>({
    userName: '',
  })

  /**
   * 远程获取登录用户信息
   */
  async function fetchLoginUser() {
    // TODO: 调用接口获取登录用户信息
    console.log('获取登录用户信息')
    const res = await getLoginUserUsingGet()
    if (res.data.code === 0 && res.data.data) {
      loginUser.value = res.data.data
    }
  }

  // 修改登录用户
  function setLoginUser(newLoginUser: any) {
    loginUser.value = newLoginUser
  }

  return { loginUser, fetchLoginUser, setLoginUser }
})
